package com.ocean.admin.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ocean.admin.core.annotation.Log;
import com.ocean.admin.core.annotation.enums.BusinessType;
import com.ocean.admin.model.dto.dictype.SysDictTypeQueryDTO;
import com.ocean.admin.model.dto.dictype.SysDictTypeSaveDTO;
import com.ocean.admin.model.dto.dictype.SysDictTypeUpdateDTO;
import com.ocean.admin.model.vo.dictype.SysDictTypeSelectVo;
import com.ocean.admin.model.vo.dictype.SysDictTypeVo;
import com.ocean.admin.service.ISysDictTypeService;
import com.ocean.core.util.response.ResultSet;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 字典类型表 前端控制器
 * </p>
 *
 * @author zhang
 * @since 2022-08-16
 */
@Tag(name = "字典类型管理")
@RestController
@RequestMapping("/admin/sys-dict-type")
public class SysDictTypeController {

    @Autowired
    private ISysDictTypeService iSysDictTypeService;

    /**
     * 分页查询字典类型
     *
     * @param queryDTO 查询条件
     * @return 结果
     */
    @Operation(summary = "分页查询字典类型")
    @PreAuthorize("@ss.hasPermission('system:dict:pageList')")
    @PostMapping(value = "pageList")
    public ResultSet<IPage<SysDictTypeVo>> pageList(@Validated @RequestBody SysDictTypeQueryDTO queryDTO) {
        return ResultSet.ok(iSysDictTypeService.pageList(queryDTO));
    }

    /**
     * 新增字典类型
     *
     * @param saveDTO 字典类型
     * @return 结果
     */
    @Operation(summary = "新增字典类型")
    @PreAuthorize("@ss.hasPermission('system:dict:saveDic')")
    @Log(title = "字典类型管理", businessType = BusinessType.INSERT)
    @PostMapping(value = "saveDicType")
    public ResultSet<String> saveDicType(@Validated @RequestBody SysDictTypeSaveDTO saveDTO) {
        return ResultSet.ok(iSysDictTypeService.saveDicType(saveDTO));
    }

    /**
     * 修改字典类型
     *
     * @param updateDTO 字典类型
     * @return 结果
     */
    @Operation(summary = "修改字典类型")
    @PreAuthorize("@ss.hasPermission('system:dict:updateDic')")
    @Log(title = "字典类型管理", businessType = BusinessType.UPDATE)
    @PutMapping(value = "updateDicType")
    public ResultSet<String> updateDicType(@Validated @RequestBody SysDictTypeUpdateDTO updateDTO) {
        return ResultSet.ok(iSysDictTypeService.updateDicType(updateDTO));
    }

    /**
     * 删除字典类型
     *
     * @param dictIds 字典类型ID
     * @return 结果
     */
    @Operation(summary = "删除字典类型")
    @PreAuthorize("@ss.hasPermission('system:dict:removeDic')")
    @Log(title = "字典类型管理", businessType = BusinessType.DELETE)
    @GetMapping("removeDicType/{dictIds}")
    public ResultSet<String> removeDicType(@PathVariable Long[] dictIds) {
        return ResultSet.ok(iSysDictTypeService.removeDicType(dictIds));
    }

    /**
     * 获取字典选择框列表
     *
     * @return 结果
     */
    @Operation(summary = "获取字典选择框列表")
    @GetMapping(value = "/optionSelect")
    public ResultSet<List<SysDictTypeSelectVo>> optionSelect() {
        return ResultSet.ok(iSysDictTypeService.optionSelect());
    }
}
